<?php
session_start();
	require_once('../includes/user.php');
	$user=new User();
	$ptm_res=$user->query("select * from points where profileid='$_SESSION[id]' AND inbox=0 ");
	$m_res=$user->query("select * from messages where receipient='$_SESSION[id]' AND inbox=0 ");
	$quiz_res=$user->query("select * from quiz_history where profile_id='$_SESSION[id]' AND inbox=0 ");
	$p=mysql_num_rows($ptm_res)+mysql_num_rows($m_res)+mysql_num_rows($quiz_res);
	$cnt=1;
?>
<table width="665" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td><div class="Innerheading">My Inbox</div></td>
  </tr>
  <tr>
    <td><div class="InnerDarkbox">
      <table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
      <?php
	  if($p>0)
	  {
	   ?>
        <tr>
          <td height="20" align="center" valign="middle" class="head">&nbsp;</td>
          <td align="center" valign="middle" class="head">&nbsp;</td>
          <td align="center" valign="middle" class="head">Request / Message</td>
          <td align="center" valign="middle" class="head">points</td>
          <td align="center" valign="middle" class="head">Status</td>
          <td align="center" valign="middle" class="head">action</td>
        </tr>
        <tr>
          <td width="11" height="20" class="head">&nbsp;</td>
          <td width="18" class="head">&nbsp;</td>
          <td width="338" class="head">&nbsp;</td>
          <td width="83" class="head">&nbsp;</td>
          <td width="84" class="head">&nbsp;</td>
          <td width="95" class="head">&nbsp;</td>
        </tr>
        <?php
			if(mysql_num_rows($ptm_res)>0)
			{
				while($ptm_row=mysql_fetch_array($ptm_res))
				{
		?>
        <tr>
          <td height="20" align="right" valign="middle">&nbsp;</td>
          <td align="left" valign="top" class="head"><?php echo $cnt; ?></td>
          <td align="left" valign="top"><?php
		  			if($ptm_row['type']==11)
					{
echo 'Academic point request ( '.$ptm_row['special1'].' Semester ) with '.$ptm_row['special2'].' %';
					}
					else if($ptm_row['type']==12)
					{
						echo 'Academic point request ( ';
						if($ptm_row['special1']==1)
						{
							echo 'I';
						}
						else if($ptm_row['special1']==2)
						{
							echo 'II';
						}
						else if($ptm_row['special1']==3)
						{
							echo 'III';
						}
						echo ' Assesment Test ) with '.$ptm_row['special2'].' %';
					}
					else if($ptm_row['type']==21)
					{
						echo 'Intra activity request on '.$ptm_row['special1'].' for the competition '.$ptm_row['special2'].' with ';
		if($ptm_row['special3']==1)
		{
			echo 'I prize';
		}
		else if($ptm_row['special3']==2)
		{
			echo 'II prize';
		}
		else if($ptm_row['special3']==3)
		{
			echo 'III prize';
		}
		else if($ptm_row['special3']==0)
		{
			echo 'Participation';
		}
					}
					else if($ptm_row['type']==22)
					{
		echo 'Inter college activity on '.$ptm_row['special1'].' for the competition '.$ptm_row['special2'].' with ';
		if($ptm_row['special3']==1)
		{
			echo 'I prize';
		}
		else if($ptm_row['special3']==2)
		{
			echo 'II prize';
		}
		else if($ptm_row['special3']==3)
		{
			echo 'III prize';
		}
		else if($ptm_row['special3']==0)
		{
			echo 'Participation';
		}
					}
		   		?></td>
          <td align="center" valign="top"><?php
		  	if($ptm_row['status']==0)
			{
				echo 'Calculating...';
			}
			else
			{
				echo $ptm_row['pt'];
			}
		   ?></td>
          <td align="center" valign="top"><?php
		  	echo $user->dispMsgStatus($ptm_row['status']); 
		  ?></td>
          <td align="center" valign="top">
          <span class="smartlink" id="request_close" onClick="requestClose(<?php echo $ptm_row['id']; ?>)">
		  <?php
		  	if($ptm_row['status']==0)
			{
				echo 'Cancel request';
			}
			else
			{
				echo 'Close';
			}
          ?>
          </span>          </td>
        </tr>
        <tr>
          <td height="20" align="right" valign="middle">&nbsp;</td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
        </tr>
        <?php
				$cnt++;
				}
			}
		?>
        <?php
			if(mysql_num_rows($quiz_res)>0)
			{
				while($quiz_row=mysql_fetch_array($quiz_res))
				{
		?>
        <tr>
          <td height="20" align="right" valign="middle">&nbsp;</td>
          <td align="left" valign="top" class="head"><?php echo $cnt; ?></td>
          <td align="left" valign="top"><?php
		  $qn_res=$user->query("select * from quiz_names where quiz_id = '$quiz_row[quiz_id]'");
			$qn_row=mysql_fetch_array($qn_res);
			echo 'Quiz :'.$qn_row['quiz_name'];
		  ?></td>
          <td align="center" valign="top"><?php echo  $quiz_row['pts'];?></td>
          <td align="center" valign="top">
          <?php
		  	$pieces = explode("/", $quiz_row['result']);
			if($pieces[1]!="")
			{
				echo $pieces[0].' Out of '.$pieces[1];
			}
			else
			{
				echo $pieces[0];
			}
		  ?>
          </td>
          <td align="center" valign="top"><span class="smartlink" id="quiz_close" onClick="quizClose(<?php echo $quiz_row['id']; ?>)" >Close</span></td>
        </tr>
        <tr>
          <td height="20" align="right" valign="middle">&nbsp;</td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
        </tr>
        <?php
				$cnt++;
				}
			}
		?>
        <?php
			if(mysql_num_rows($m_res)>0)
			{
				while($m_row=mysql_fetch_array($m_res))
				{
		?>
        <tr>
          <td height="20" align="right" valign="middle">&nbsp;</td>
          <td><?php echo $cnt; ?></td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td align="center" valign="top"><?php
		  	echo $user->dispMsgStatus($m_row['status']); 
		  ?></td>
          <td>&nbsp;</td>
        </tr>
        <tr>
          <td height="20" align="right" valign="middle">&nbsp;</td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
        </tr>
        <?php
				$cnt++;
				}
			}
		}
		else
		{
		?>
        <div align="center">There are no messages in your inbox !!!</div>
        <?php
		}
		?>
      </table>
    </div></td>
  </tr>
</table>
